#!/usr/bin/python
# -*- coding: utf-8 -*-
#Under the terms of the General Public License v.3
#For more information see LICENSE.txt

import pygame
from pygame.sprite import Sprite
from InfoImages import *

class Element(Sprite):

	def __init__(self, obj, posX, posY):
		self.infoImages = InfoImages()
		self.image = self.infoImages.getImage(obj)
		self.rect = self.image.get_rect()
		self.posX = posX
		self.posY = posY

	def getCenter(self):
		x = (self.getWidth() / 2) + self.getPosX()
		y = (self.getHeight() / 2) + self.getPosY()
		return (x, y)

	def getPosX(self):
		return self.posX
	
	def setPosX(self, posX):
		self.posX = posX

	def getPosY(self):
		return self.posY
	
	def setPosY(self, posY):
		self.posY = posY

	def setPosXY(posX, posY):
		self.posX = posX
		self.posY = posY

	def getPosXY(self):
		return (self.posX, self.posY)

	def getWidth(self):
		return self.rect.width

	def getHeight(self):
		return self.rect.height

	def getWidthHeigth(self):
		return (self.width, self.heigth)

	def update(self):
		pass
	
	def paint(self, surface):
		surface.blit(self.image, (posX, posY))

	def collides(self, element):
		up = self.posY
		down = self.posY + self.height
		left = self.posX
		right = self.posX + self.width

		if ( up <= (element.getPosY() + element.getHeight()) ):
			return True
		if ( down >= element.getPosY() ):
			return True
		if ( left <= (element.getPosX() + element.getWidth()) ):
			return True
		if ( right >= element.getPosX() ):
			return True

		return False


"""	def collides(self, element):
		reldistX = abs(self.posX - element.posX)
		reldistY = abs(self.posY - element.posY)
		relYdist = abs (self.heigth - element.heigth)
		relXdist = abs (self.width - element.width)
		if reldistX < relXdist and reldistY < relYdist:
			return True
		return False
"""
